package com.zzptc.zzsgz.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.zzsgz.myapplication.entity.UserFactory;
import com.zzptc.zzsgz.myapplication.service.UserFactoryService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class Main2Activity extends AppCompatActivity {
    private static final String TAG = "Main2Activity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        getUserFactory();
    }

    private void getUserFactory() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://www.hnzzsgz.cn:5001/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        UserFactoryService userFactoryService = retrofit.create(UserFactoryService.class);

        Call<UserFactory> info = userFactoryService.getInfo(1);

        info.enqueue(new Callback<UserFactory>() {
            @Override
            public void onResponse(Call<UserFactory> call, Response<UserFactory> response) {
                UserFactory userFactory = response.body();
                Log.d(TAG, "onResponse: "+userFactory.getData().get(0).getNickName());
            }

            @Override
            public void onFailure(Call<UserFactory> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());

            }
        });


    }
}
